package com.example.crm.web.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 异常全局处理
 * @author lenovo
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 出现异常之后会跳转到此方法
     * @param request
     * @param e
     * @return
     */
    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView unauthorizedExceptionHandler(HttpServletRequest request,UnauthorizedException e){
        //设置跳转路径
        ModelAndView mv = new ModelAndView("403");
        //将异常对象传递过去
        mv.addObject("exception",e);
        //获得请求路径
        mv.addObject("url",request.getRequestURL());
        return mv;
    }
}